<?php
/**
 * View parcial para campo form admin
 * @param campo
 * @param cabecalho
 * @param valor
 * @param required
 * @param hint
 */
$campo = $this->campo;
$cabecalho = $this->cabecalho;
$valor = $this->valor;
$hint = $this->hint;
$r = $this->r;
$rsQuiz = $this->quiz;
?>
<link rel="stylesheet" type="text/css" href="<?php echo $this->baseUrl('_css/quiz1.css');?>" media="screen" />
<script type="text/javascript">
<!--
var nQuestao;
$(function() {
	nQuestao = $('.questionWrap').length -1;
	if (nQuestao == 1) addQuestao();
});

function addAlternativa(idQuestionario, obj) {
	var html = $('#molduraAlternativa').html();
	var nPergunta = $(obj).parent('div').siblings('table').find('textarea[id*=ans]').length + 1;
	html = html.replace(/{r}/g, nPergunta).replace(/{q}/g, idQuestionario);
	var div = $(obj).parent('div').siblings('table').find('#answers' + idQuestionario).append(html);
	$('.questionWrap:visible').find('input, textarea').attr('disabled', false);
	var rule = $(html).find('textarea')[0].name;
	settings.rules[rule] = { required: true };
		
}

function removeAlternativa(obj) {
	$(obj).parents('[id*=ans]:first').remove();
}

function addQuestao() {
	var htmlQ = $('#molduraQuestionario').html();
	nQuestao = $('.questionWrap').length -1;
	htmlQ = htmlQ.replace(/{q}/gi, nQuestao);
	$(htmlQ).find('textarea').each(function() {
		settings.rules[this.name] = {required: true};
	});
	$('.questionWrap:visible:last').after(htmlQ);
	$('.questionWrap:visible:last').siblings('.questionWrap:last').show().find('.doWysiwyg').wysiwyg();
	$('.questionWrap:visible').find('input, textarea').attr('disabled', false);
}

function removeQuestao(obj) {
//	$(obj).parents('.questionWrap:first').find('.wysiwyg').destroy();
	//$(obj).parents('.questionWrap:first').find('input, textarea').attr('disabled', true);
	$(obj).parents('.questionWrap:first').remove();

	
}
//-->
</script>
<div class="questionWrap"></div>
<?php
$p = 1;
foreach ((array)$rsQuiz as $i => $perguntas) {
	$a = 1;
	$iPergunta = current($perguntas);
?>
<div class="questionWrap">
<input name="id_perguntas[]" value="<?php echo $i;?>" type="hidden" />
<div style="width: auto; padding: 0px; margin: 0px; border: 1px solid #CCCBCA; border-bottom: 2px solid #CCCBCA; background: url(<?php echo $this->baseUrl('_img/q-foot-bg.png');?>) bottom repeat-x #fff;">
<div style="width: auto; padding: 4px 6px 4px 6px;">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
	<tbody>
		<tr>
			<td>
				<span style="font-size: 1.5em;">Questão</span>
				<strong id="quesNum_<?php echo $p;?>" style="font-size: 1.5em;"><?php echo $p;?>. </strong> <small
				style="color: #777;">Questão de única escolha</small>
			
			</td>
<?php
if ($p >= 2) {
?>

					<td valign="middle" align="right">&nbsp;<a style="cursor: pointer;" onclick="removeQuestao(this);"><img width="15" align="right" alt="Excluir esta pergunta" title="Excluir esta pergunta" src="<?php echo $this->baseUrl('_img/icon_delete.gif');?>"></a></td>
<?php
}
else {
?>
			<td valign="middle" align="right"></td>
<?php
}
?>
		</tr>
	</tbody>
</table>
</div>
<textarea class="wysiwyg" style="height: 100px;" id="questao<?php echo $p;?>" name="pergunta[<?php echo $p;?>]" cols="1" rows="1" ><?php echo $iPergunta['pergunta'];?></textarea>
<span role="presentation" style="position: absolute;" tabindex="-1"></span></span>
<table border="0" style="background: #fff; width: auto; color: #777; font-size: 0.9em; padding: 5px;">
	<tbody>
		<tr>
			<td colspan="2">

				<div id="answers<?php echo $p;?>">
<?php
	// campos de alternativas
	foreach ($perguntas as $resposta) {
?>					<div id="ans<?php echo $p;?>_<?php echo $a;?>">
						<table>
							<tbody>
								<tr>
									<td style="width: 0px;">
										<small>Resposta <?php echo $a;?></small>
										<textarea style="padding: 10px; width:479px !important; height: 17px;" class="ansO {validate: {required: true}}" id="answer<?php echo $p;?>_<?php echo $a;?>" name="resposta[<?php echo $p;?>][<?php echo $a;?>]" rows="2"><?php echo $resposta['resposta'];?></textarea>
										<input type="hidden" name="id_respostas[]" value="<?php echo $resposta['id_respostas'];?>" />
									</td>
									<td align="center" style="vertical-align: bottom; padding:10px 0px;"><label class="anslabel">
										<input class="{validate: {required: true}}" type="radio" value="<?php echo $a;?>" id="corr<?php echo $p;?>_<?php echo $a?>" name="correta[<?php echo $p;?>]" title="marcar como resposta correta" style="float: left;" <?php echo (!empty($resposta['correta'])) ? 'checked="checked"' : null;?> />&nbsp;resposta correta</label>
									</td>
<?php
		if ($a >= 3) {
?>
									<td style="vertical-align: middle">
										<a class="deletar" onmouseout="this.style.border='1px solid #dddddd';this.style.background='#fff';" onmouseover="this.style.border='1px solid #CF0000'; this.style.background='#FFE5DF';" onclick="removeAlternativa(this);" title="Remover esta alternativa">x</a>
									</td>
<?php
		}
?>
								</tr>
							</tbody>
						</table>
					</div>
<?php
		$a++;
	}
?>
				</div>
			</td>
		</tr>
	</tbody>
</table>
<div  class="masRespostas">
	<a onclick="addAlternativa(<?php echo $p;?>, this);" title="Adicionar nova alternativa de resposta." style="text-decoration: none;"><strong style="-moz-border-radius: 10px; border-radius: 10px; border: 1px solid #ddd; background: url(<?php echo $this->baseUrl('_img/q-foot-bg.png');?>) repeat-x #fff; padding: 2px 6px; cursor: pointer;">+ Resposta</strong></a>
</div>
</div>
</div>
<?php
	$p++;
}
?>
<div id="molduraQuestionario">
	<div class="questionWrap" style="display: none;">
		<div style="width: auto; padding: 0px; margin: 0px; border: 1px solid #CCCBCA; border-bottom: 2px solid #CCCBCA; background: url(<?php echo $this->baseUrl('_img/q-foot-bg.png');?>) bottom repeat-x #fff;">
		<div style="width: auto; padding: 4px 6px 4px 6px;">
		<table style="width:100%;" cellspacing="0" cellpadding="0" border="0">
			<tbody>
				<tr>
					<td>
						<span style="font-size: 1.5em;">Questão</span>
						<strong id="quesNum_{q}" style="font-size: 1.5em;">{q}. </strong> <small
						style="color: #777;">Questão de única escolha</small>
					
					</td>
					<td valign="middle" align="right">&nbsp;<a style="cursor: pointer;" onclick="removeQuestao(this);"><img width="15" align="right" alt="Excluir esta pergunta" title="Excluir esta pergunta" src="<?php echo $this->baseUrl('_img/icon_delete.gif');?>"></a></td>
				</tr>
			</tbody>
		</table>
		</div>
		<textarea disabled="disabled" style="height: 100px;" class="doWysiwyg" id="questao{q}" name="pergunta[{q}]" cols="1" rows="1"></textarea>
		<span role="presentation" style="position: absolute;" tabindex="-1"></span>
		<table border="0" style="background: #fff; width:100%; color: #777; font-size: 0.9em; padding: 5px;">
			<tbody>
				<tr>
					<td colspan="2">
						<div id="answers{q}">
							<div id="ans{q}_1">
								<table>
									<tbody>
										<tr>
											<td style="width: 0px;">
											<small>Resposta 1</small>
											<textarea disabled="disabled" style="padding: 10px; width:479px !important; height: 17px;" class="ansO" id="answer{q}_1" name="resposta[{q}][1]" rows="2"></textarea></td>
											<td align="center" style="vertical-align: bottom; padding:10px 0px;"><label class="anslabel">
												<input disabled="disabled" type="radio" value="1" id="corr{q}_1" name="correta[{q}]" title="marcar como resposta correta" style="float: left;" />&nbsp;resposta correta</label>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
							<div id="ans{q}_2">
								<table>
									<tbody>
										<tr>
											<td style="width: 0px;">
											<small>Resposta 2</small>
												<textarea disabled="disabled" style="padding: 10px; width:479px !important; height: 17px;" class="ansO" id="answer{q}_2" name="resposta[{q}][2]" rows="2"></textarea>
											</td>
											<td align="center" style="vertical-align: bottom; padding:10px 0px; "><label class="anslabel">
												<input disabled="disabled" type="radio" value="2" id="corr{q}_2" name="correta[{q}]" title="marcar como resposta correta" style="float: left;">&nbsp;resposta correta</label>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
					</td>
				</tr>
			</tbody>
		</table>
		<div class="masRespostas">
			<a onclick="addAlternativa('{q}', this);" title="Adicionar nova alternativa de resposta." style="text-decoration: none;"><strong style="-moz-border-radius: 10px; border-radius: 10px; border: 1px solid #ddd; background: url(<?php echo $this->baseUrl('_img/q-foot-bg.png');?>) repeat-x #fff; padding: 2px 6px; cursor: pointer;">+ Resposta</strong></a>
            <div style="clear:both;"></div>
		</div>
		</div>
	</div>
</div>

<div id="molduraAlternativa" style="display: none;">
	<div id="ans{q}_{r}">
		<table>
			<tbody>
				<tr>
					<td style="width: 0px;">
						<small>Resposta {r}</small>
						<textarea disabled="disabled" style="padding: 10px; width:479px !important; height: 17px;" class="ansO {required: {validate: true}}" id="answer{q}_{r}" name="resposta[{q}][{r}]" rows="2"></textarea>
					</td>
					<td align="center" style="vertical-align: bottom; padding:10px 0px;">
						<label class="anslabel"><input disabled="disabled" type="radio" value="{r}" id="corr{q}_{r}" name="correta[{q}]" title="marcar como resposta correta" style="float: left;">&nbsp;resposta correta</label>
					</td>
					<td style="vertical-align: middle;">
						<a class="deletar" onmouseout="this.style.border='1px solid #dddddd';this.style.background='#fff';" onmouseover="this.style.border='1px solid #CF0000'; this.style.background='#FFE5DF';" onclick="removeAlternativa(this);" title="Remover esta alternativa">x</a>
					</td>
				</tr>
			</tbody>
		</table>
	</div>
</div>

<div style="width:800px;" class="add-questions-box" id="qButtons">
	<span class="separator">&nbsp;</span>
	<div class="clear"></div>  	
	<a onclick="addQuestao();" href="javascript:void(0);" class="button">Nova questão</a>
	&nbsp;&nbsp;
	<br />
</div>
<br />
<br />